Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

179
Vistas
Nodejs | Object property is available but it's returning 'undefined'

I've been trying to solve this for about 2 hours. I am returning an object in Nodejs. This object has 3 properties. I can access the first two, but when I try to access the third property, I get the 'undefined' warning. I'm about to go crazy can you help me please?

Request:

  const categories = await Categories.find({}); //mongoose query
  console.log(categories[0]); //its returning Object
  console.log(categories[0].category); //its returning  []
  console.log(categories[0]._id); //its returning  new ObjectId("6257233b897c3b8785ff625b")
  console.log(categories[0].mainCategories); //its returning  undefined ?? wtf?!
  console.log(categories[0].hasOwnProperty("category")); //its returning false
  console.log(categories[0].hasOwnProperty("_id")); //its returning false
  console.log(categories[0].hasOwnProperty("mainCategories")); //its returning false

Object Result:

{
  category: [],
  _id: new ObjectId("6257233b897c3b8785ff625b"),
  mainCategories: [
    { id: 1000010100, name: 'Konut', subCategories: [Array] },
    { id: 1000010200, name: 'Devremülk', subCategories: [Array] },
    { id: 1000020100, name: 'İşyeri', subCategories: [Array] },
    { id: 1000020200, name: 'Arazi', subCategories: [Array] },
    {
      id: 1000020300,
      name: 'Turistik İşletme',
      subCategories: [Array]
    }
  ]
}

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The answers given by Cristian Traìna and VebDav caused lightning in my brain. I couldn't find the exact solution to the problem on the internet. But different problems guided me. The problem stems from my stupidity. I forgot to enter the mainCategories field in the mongoose category schema. I added this and its fixed. Thank you so much everyone for your answers.

enter image description here

And now its returning mainCategories :)

enter image description here

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda